package com.brook;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class TaskAssigneeUel {

    @Test
    public void testDeployment() {
        //1.创建processEngine
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.获取RepositoryService
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        //3.使用service进行流程的部署，定义一个流程的名称，把bpmn和png部署到数据库中
        Deployment deploy = repositoryService.createDeployment()
                .name("出差申请-uel")
                .addClasspathResource("bpmn/evection-uel.bpmn")
                .deploy();
        //4.输出部署信息
        System.out.println("流程部署id="+deploy.getId());
        System.out.println("流程部署名字"+deploy.getName());
    }


    //启动流程实例
    @Test
    public void startAssigneeUel(){
        //1.获取流程引擎
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.获取RunTimeService
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        //设定assignee的key，用uel表达式替换
        Map<String, Object> assigneeMap = new HashMap<>();
        assigneeMap.put("assignee0","张三");
        assigneeMap.put("assignee1","李经理");
        assigneeMap.put("assignee2","王总经理");
        assigneeMap.put("assignee3","汤财务");
        //3.启动流程实例
        runtimeService.startProcessInstanceByKey("myEvection1",assigneeMap);
    }
}
